package com.xx.job.controller.system;


import com.xx.job.common.Result;
import com.xx.job.controller.dto.PageDTO;
import com.xx.job.entity.system.SysRole;
import com.xx.job.service.system.SysRoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xx.job.controller.base.BaseController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liangcy
 * @since 2021-01-14
 */
@RestController
@RequestMapping("/api/v1")
public class SysRoleController extends BaseController {

    @Autowired
    private SysRoleService sysRoleService;

    @GetMapping("/rolelist")
    public Result rolelist(PageDTO pageDTO, SysRole sysRole){
        Map<String, Object> stringObjectMap = sysRoleService.sysRoleList(pageDTO, sysRole);
        return Result.success(stringObjectMap);
    }

    @PostMapping("/role")
    public Result addRole(@RequestBody SysRole sysRole){
        return Result.success(sysRoleService.add(sysRole));
    }

    @GetMapping("/role/{id}")
    public Result selectRole(@PathVariable Long id){
        return Result.success(sysRoleService.select(id));
    }

    @DeleteMapping("/role/{ids}")
    public Result deleteRole(@PathVariable List<Long> ids){
        return Result.success(sysRoleService.deleteBatchIds(ids));
    }

    @PutMapping("/role")
    public Result updateRole(@RequestBody SysRole sysRole){
        return Result.success(sysRoleService.update(sysRole));
    }

    @PutMapping("/roledatascope")
    public Result roleDataScope(@RequestBody SysRole sysRole){
        if(StringUtils.isBlank(sysRole.getDataScope())){
            Result.errorMsg(400,"请选择权艰范围！");
        }
        return Result.success(sysRoleService.roleDataScope(sysRole));
    }

}

